<?php
include(LIBRARY_PATH.'/adodb/adodb.inc.php');

function linkDB()
{
	$conn = &ADONewConnection('sqlite');
	$done = $conn->PConnect(DB_FILE);
	//$ADODB_CACHE_DIR = '';
	//$conn->debug = true;
	
	return $conn;
}

function InsertData($conn, $tableName, &$dataArray, $wherePar = 'id = -1' )
{
	$rs = $conn->Execute('SELECT * FROM '.$tableName.' WHERE '.$wherePar); 
	$insertSQL = $conn->GetInsertSQL($rs, $dataArray); 
    return $conn->Execute($insertSQL);
}

function UpdateData($conn, $tableName, &$dataArray, $wherePar )
{
	$rs = $conn->Execute('SELECT * FROM '.$tableName.' WHERE '.$wherePar);
	$updateSQL = $conn->GetUpdateSQL($rs, $dataArray); 
    return $conn->Execute($updateSQL);
}

function DeleteData($conn, $tableName, $wherePar){
	return $conn->Execute('DELETE FROM '.$tableName.' WHERE '.$wherePar);
}

function FP($defaultParameter,$headFix = '',$footFix = '')
{
	$FormatParameter = $defaultParameter;
	$FormatParameter = '\''.$headFix.$FormatParameter.$footFix.'\'';
	return $FormatParameter;
}

$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;

function utf82gb($sourceSting)
{
	return mb_convert_encoding($sourceSting,'gb2312','utf-8');
}
function gb2utf8($sourceSting)
{
	return mb_convert_encoding($sourceSting,'utf-8','gb2312');
}
?>